﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Management.BLL;
using Util.Webs.EasyUi.Trees;
using Util.Webs.EasyUi.Results;
using Management.Entity;

namespace MET.Web.Controllers
{
    public class PermissionsController : Controller
    {
        //
        // GET: /Permissions/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult GetAll()
        {
            PermissionService service = new PermissionService();
            var v = service.GetAllPermission();
            return Json(v);
        }

        [HttpPost]
        [UIExceptionResult]
        public ActionResult Add(Permission entity)
        {
            if (entity != null && entity.ParentID>0)
            {
                PermissionService service = new PermissionService();
                var result = service.Add(entity);
                if (result)
                    return Content("OK");
                else
                    return Content("ERROR");
            }
            else
                return Content("ERROR");
        }
        [UIExceptionResult]
        public ActionResult GetInfo(int id)
        {
            PermissionService service = new PermissionService();
            var V = service.GetPermissionInfo(id);
            return Json(V, JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public ActionResult Update(Permission entity)
        {
            PermissionService service = new PermissionService();
            var v = service.Update(entity);
            if (v)
            {
                return Content("OK");
            }
            return Content("ERROR");
        }
        [HttpPost]
        public ActionResult Delete(int id)
        {
            PermissionService service = new PermissionService();
            var entity = service.GetPermissionInfo(id);
            var v = service.Delete(entity);
            if (v)
            {
                return Content("OK");
            }
            return Content("ERROR");
        }
    }
}
